<?php $this->display(tpl('head')); ?>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>已安装模块管理</legend>
</fieldset>
<style>
	.my-tabel thead tr td,.my-tabel tbody tr td{
		text-align: center;
	}
	.layui-form-switch{
		margin-top: 0;
	}
</style>

    <table class="layui-table my-tabel layui-form" lay-filter="test3">
    	<thead>
    		<tr>
    			<td width="50">id</td>
    			<td>模块名称</td>
    			<td>表前戳</td>
    			<td>目录</td>
    			<td>绑定域名</td>
    			<td width="100">是否在会员显示</td>
    			<td width="50">状态</td>
    			<td width="100">操作</td>
    		</tr>
    	</thead>
		<tbody>
			<?php foreach($modular as $row)	{ ?>
			<tr>
				<td><?php echo $row[id] ?></td>
    			<td onclick=" return edit_input(this,'模块名称','name')" id="name_<?php echo $row[id] ?>" iid="<?php echo $row[id] ?>"><?php echo $row[name] ?></td>
    			<td><?php echo $row[table] ?></td>
    			<td><?php echo $row[dir] ?></td>
    			<td onclick=" return edit_input(this,'domain','domain')" id="domain_<?php echo $row[id] ?>" iid="<?php echo $row[id] ?>"><?php echo $row[domain] ?></td>
    			<td><input type="checkbox" id="<?php echo $row[id] ?>" <?php if($row[user_show]) echo 'checked'?> name="user_show"  lay-filter="user_show" lay-skin="switch"  lay-text='开启|关闭'></td>
    			<td><input type="checkbox" id="<?php echo $row[id] ?>" <?php if($row[state]) echo 'checked'?> name="state"  lay-filter="state" lay-skin="switch"  lay-text='开启|关闭'></td>
    			<td>
    				<a class="layui-btn layui-btn-xs layui-btn-normal" href="/admin/modular/copy/id_<?php echo $row[id] ?>">复制</a>
    				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要卸载本模块？卸载以后，所有模块数据将被擦除，此方法不可逆。')"  href="/admin/modular/del/id_<?php echo $row[id] ?>">卸载</a>
    			</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>未安装模块</legend>
</fieldset>
	<table class="layui-table my-tabel layui-form" lay-filter="test3">
    	<thead>
    		<tr>
    			<td>模块名称</td>
    			<td>表前戳</td>
    			<td>目录</td>
    			<td>开发者信息</td>
    			<td>状态</td>
    			<td>版本</td>
    			<td>更新时间</td>
    			<td>操作</td>
    		</tr>
    	</thead>
		<tbody>
			<?php foreach($install as $row)	{ ?>
			<tr>

    			<td><?php echo $row[modular][name] ?></td>
    			<td><?php echo $row[modular][table] ?></td>
    			<td><?php echo $row[dir] ?></td>
    			<td>
    				<p>开发者:<?php echo $row[modular][developer] ?></p>
    				<p>联系email:<?php echo $row[modular][email] ?></p>
    				<p>开发公司：<?php echo $row[modular][firm] ?></p>
    			</td>
    			<td>待安装</td>
    			<td><?php echo $row[modular][version] ?></td>
    			<td><?php echo $row[modular][update] ?></td>
    			<td>
    				<a class="layui-btn layui-btn-xs layui-btn-normal" href="/admin/modular/install/dir_<?php echo $row[dir] ?>">安装</a>
    				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要删除本模块？此方法不可逆')"  href="/admin/modular/del/step_install/dir_<?php echo $row[dir] ?>">删除</a>
    			</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
<script>
function edit_input(a,b,c){
	
	$('#'+a.id).removeAttr("onclick"); 
	var iid =$('#'+a.id).attr('iid');
	a.innerHTML='<input type="text"  class="layui-input"  name="name" id="name" value="'+a.innerHTML+'" />';
	$("#name").focus();
	$("#name").blur(function(){
		var value=$(this).attr("value");
		$.ajax({
			url:"/admin/modular/edit/",
			type: 'POST',
			data:{'value':value,'id':iid,'step':c,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					layer.tips('当前'+b+'修改为：'+value,a);
					$('#'+a.id).attr("onclick"," return edit_input(this)");
					a.innerHTML=data.value;
				}else{
					a.innerHTML=data.value;
					$('#'+a.id).attr("onclick"," return edit_input(this)"); 
					layer.tips(data.text, a);
				}
			}	
		});
		
		layer.tips('当前模块名称修改为：'+value,a);
	});
}

layui.use(['form','table'], function(){
	var form = layui.form;
	var table = layui.table;

	//监听指定开关
	form.on('switch(state)', function(obj){
	  	var state= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/modular/state/",
			type: 'POST',
			data:{'state':state,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				console.log(data);
				if(data.code=='0'){
					if(state==0){
						layer.tips("本模块已关闭", obj.othis);
					}else{
						layer.tips("本模块已开启", obj.othis);
				  	}
				}else{
					layer.tips(data.text, obj.othis);
				}
			
				
			}	
		});
	   
	});
	form.on('switch(user_show)', function(obj){
	  var user_show= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/modular/user_show/",
			type: 'POST',
			data:{'user_show':user_show,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					if(user_show==0){
						layer.tips("已关闭前台显示功能", obj.othis);
					}else{
						layer.tips("已开启前台显示功能", obj.othis);
				  }
				}else{
					layer.tips(data.text, obj.othis);
				}
			}	
		});
	});

});

</script>
<?php $this->display(tpl('foot')); ?>
